package com.usian.tu.controller;

import com.apis.fabu.AdFabuApi;
import com.sun.org.apache.regexp.internal.RE;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.media.dtos.WmNewsDto;
import com.usian.model.media.pojos.WmNews;
import com.usian.tu.service.FabuService;

import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("wemediatu/api/vi/")
public class FabuControler implements AdFabuApi {

    @Resource
    private FabuService fabuService;

    @GetMapping("findbyid/{id}")
    @Override
    public ResponseResult findbyid(@PathVariable Integer id) {
        return fabuService.findbyid(id);
    }


    @RequestMapping("zidongshenhe")
    public  List<Integer> zidongshenhe(){
        return fabuService.zidongshenhe();
    }

//上架或者下架
    @RequestMapping("shangxiajia")
    public ResponseResult shangxiajia(@RequestBody WmNews wmNews){
        return fabuService.shangxiajia(wmNews);

    }

    //   审核第一步调用的方法 根据id获取整条记录
    @GetMapping("getfindbyid")
    @Override
    public WmNews getfindbyid(@RequestParam Integer id) {
        System.out.println("---------------------getfindbyid执行成功--------------------------------------");
        System.out.println("---------------------getfindbyid执行成功--------------------------------------");
        return fabuService.getById(id);

    }

    @GetMapping("getbynew")
    @Override
    public WmNews getbynew( Integer id) {
        System.out.println("---------------------getfindbyid执行成功--------------------------------------");
        System.out.println("---------------------getfindbyid执行成功--------------------------------------");
        return fabuService.getbynew(id);

    }



    //文章发布查询
    @PostMapping("fabulist")
    @Override
    public ResponseResult list(@RequestBody WmNewsDto dto) {
        return fabuService.list(dto, null);
    }

    //    这里是 对应 // post文章(新建)  get拉取文章列表
    @PostMapping("submit")
    @Override
//    获取信息 并对里面的状态判断 是1还是0  状态 提交为1  草稿为0
    public ResponseResult submit(@RequestBody WmNewsDto dto) {
        if (dto.getStatus() == 1) {
            return fabuService.list(dto, 1);
        } else {
            return fabuService.list(dto, 0);
        }

    }

    @PostMapping("updatewmnews")
    @Override
    public ResponseResult updatewmnews(@RequestBody WmNews wmNews) {
        return fabuService.updateStatusAndReason(wmNews);
    }
}
